package unit6.part6;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class ComparatorTest {
    public static void main(String[] args) {
        List<Employee> list = new ArrayList<>();
        list.add(new Employee("A", 100, 22));
        list.add(new Employee("B", 80, 19));
        list.add(new Employee("C", 80, 18));

        Comparator<Employee> comparator = (a, b) -> {// 大于0为a>b，小于为a<b，等于0为a=b
            if (a.score == b.score) {
                return a.age - b.age;
            } else {
                return b.score - a.score;
            }
        };

        list.sort(comparator);// 由小到大
        System.out.println(list);
    }
}

class Employee {
    String name;
    int score;
    int age;

    public Employee(String name, int score, int age) {
        this.name = name;
        this.score = score;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                '}';
    }
}
